// 设置系统类型定义
// 定义所有设置相关的接口和枚举

// 设置分类枚举
export enum SettingsCategory {
  Editor = 'editor',
  Appearance = 'appearance',
  Keyboard = 'keyboard',
  Files = 'files',
  Extensions = 'extensions',
  Advanced = 'advanced'
}

// 设置项类型枚举
export enum SettingType {
  Boolean = 'boolean',
  Number = 'number',
  String = 'string',
  Select = 'select',
  MultiSelect = 'multiselect',
  Color = 'color',
  Shortcut = 'shortcut',
  Font = 'font'
}

// 设置项验证规则
export interface SettingValidation {
  required?: boolean;
  min?: number;
  max?: number;
  pattern?: string;
  options?: Array<{ value: any; label: string; description?: string }>;
  custom?: (value: any) => string | null; // 返回错误信息或null
}

// 基础设置项接口
export interface BaseSetting {
  id: string;
  name: string;
  description: string;
  category: SettingsCategory;
  type: SettingType;
  defaultValue: any;
  currentValue: any;
  validation?: SettingValidation;
  tags?: string[]; // 用于搜索
  group?: string; // 设置组，用于界面分组显示
  order?: number; // 显示顺序
  hidden?: boolean; // 是否隐藏
  readonly?: boolean; // 是否只读
  requiresRestart?: boolean; // 是否需要重启应用
}

// 编辑器设置
export interface EditorSettings {
  // 基础设置
  fontSize: number;
  fontFamily: string;
  lineHeight: number;
  tabSize: number;
  insertSpaces: boolean;
  wordWrap: boolean;
  showLineNumbers: boolean;
  showMinimap: boolean;
  showWhitespace: boolean;
  showIndentGuides: boolean;
  
  // 代码编辑
  autoSave: boolean;
  autoSaveDelay: number;
  formatOnSave: boolean;
  formatOnPaste: boolean;
  trimTrailingWhitespace: boolean;
  insertFinalNewline: boolean;
  
  // 代码提示
  quickSuggestions: boolean;
  suggestOnTriggerCharacters: boolean;
  acceptSuggestionOnEnter: boolean;
  snippetSuggestions: boolean;
  
  // 代码折叠
  folding: boolean;
  foldingStrategy: 'auto' | 'indentation';
  showFoldingControls: 'always' | 'mouseover';
  
  // 光标和选择
  cursorBlinking: 'blink' | 'smooth' | 'phase' | 'expand' | 'solid';
  cursorStyle: 'line' | 'block' | 'underline';
  multiCursorModifier: 'ctrlCmd' | 'alt';
  
  // 滚动
  smoothScrolling: boolean;
  mouseWheelScrollSensitivity: number;
  fastScrollSensitivity: number;
}

// 外观设置
export interface AppearanceSettings {
  // 主题
  theme: 'light' | 'dark' | 'auto';
  followSystemTheme: boolean;
  customTheme?: string;
  
  // 颜色
  accentColor: string;
  backgroundColor: string;
  foregroundColor: string;
  
  // 布局
  sidebarPosition: 'left' | 'right';
  panelPosition: 'bottom' | 'right';
  showActivityBar: boolean;
  showStatusBar: boolean;
  showToolbar: boolean;
  
  // 字体
  uiFontFamily: string;
  uiFontSize: number;
  
  // 图标
  iconTheme: string;
  showFileIcons: boolean;
  showFolderIcons: boolean;
  
  // 动画
  enableAnimations: boolean;
  animationDuration: number;
  
  // 透明度
  windowOpacity: number;
  sidebarOpacity: number;
}

// 快捷键设置
export interface KeyboardSettings {
  shortcuts: Record<string, string>;
  enableGlobalShortcuts: boolean;
  customShortcuts: Record<string, string>;
  conflictResolution: 'warn' | 'override' | 'disable';
}

// 文件设置
export interface FileSettings {
  // 文件关联
  associations: Record<string, string>;
  
  // 编码
  defaultEncoding: string;
  autoGuessEncoding: boolean;
  
  // 换行符
  eol: 'auto' | 'lf' | 'crlf';
  
  // 文件监听
  watcherExclude: string[];
  usePolling: boolean;
  
  // 自动保存
  autoSave: 'off' | 'afterDelay' | 'onFocusChange' | 'onWindowChange';
  autoSaveDelay: number;
  
  // 备份
  enableBackup: boolean;
  backupLocation: string;
  maxBackupFiles: number;
}

// 扩展设置
export interface ExtensionSettings {
  enabledExtensions: string[];
  disabledExtensions: string[];
  autoUpdate: boolean;
  checkUpdateInterval: number;
  allowPrerelease: boolean;
}

// 高级设置
export interface AdvancedSettings {
  // 性能
  maxMemoryUsage: number;
  enableGPUAcceleration: boolean;
  
  // 调试
  enableDebugMode: boolean;
  logLevel: 'error' | 'warn' | 'info' | 'debug';
  
  // 网络
  proxySettings: {
    enabled: boolean;
    host: string;
    port: number;
    username?: string;
    password?: string;
  };
  
  // 实验性功能
  experimentalFeatures: string[];
}

// 完整设置配置
export interface SettingsConfig {
  editor: EditorSettings;
  appearance: AppearanceSettings;
  keyboard: KeyboardSettings;
  files: FileSettings;
  extensions: ExtensionSettings;
  advanced: AdvancedSettings;
}

// 设置更改事件
export interface SettingChangeEvent {
  settingId: string;
  oldValue: any;
  newValue: any;
  category: SettingsCategory;
  timestamp: number;
}

// 设置导入导出格式
export interface SettingsExport {
  version: string;
  timestamp: number;
  settings: Partial<SettingsConfig>;
  metadata?: {
    appVersion: string;
    platform: string;
    exportedBy?: string;
  };
}

// 设置搜索结果
export interface SettingSearchResult {
  setting: BaseSetting;
  matchType: 'name' | 'description' | 'tag';
  matchText: string;
  score: number;
}

// 设置验证结果
export interface SettingValidationResult {
  isValid: boolean;
  errors: string[];
  warnings: string[];
}
